<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <meta http-equiv="Pragma" content="no-cache"/>
    <meta http-equiv="no-cache"/>
    <meta http-equiv="Expires" content="-1"/>
    <meta http-equiv="Cache-Control" content="no-cache"/>
    <title>编辑部门---审批人</title>

    <script type="text/javascript">
      Ext.onReady(function(){
        Ext.QuickTips.init();
        //部门主管的数据
 

    departmentId = <%= params[:id] %>;


        var managerDS = new Ext.data.Store({
          proxy:new Ext.data.HttpProxy({url:'/department/getManagerForDepartment?departmentid='+departmentId}),
          autoLoad:true,
          reader:new Ext.data.JsonReader({
          }, [

            {name:'id'},
            {name:'name'}

          ])
        });

        var editDepartmentForm = new Ext.form.FormPanel({
          width:300,
          //labelAlign: 'top',
          url:'/department/update?id='+departmentId,
          buttonAlign:'center',
          autoHeight:true,
          fileUpload: true,
          bodyStyle: 'padding:5px',
          labelWidth:100,
          waitMsgTarget: true,
          frame: true,
          reader:new Ext.data.JsonReader({
          },[
            {name:'id'},
            {name:'name'},
            {name:'manager_id'}
          ]
        ),
          items:[{
              xtype:'textfield',
              fieldLabel: '部门名称',
              name: 'name',
              allowBlank:false,
              anchor:'90%'
            }
            /*
            ,
            {
              xtype:'textfield',
              fieldLabel: '部门主管',
              name: 'manager',
              allowBlank:false,
              anchor:'90%'
            }
             */
            
            ,{
              xtype:'combo',
              store: managerDS,
              displayField:'name',
              hiddenName:'manager_id',
              blankText:'请选择主管',
              emptyText:'请选择主管',
              valueField:'id',
              typeAhead: true,
              allowBlank:false,
              minChars:1,
              anchor: '95%',
              mode: 'remote',
              fieldLabel:'部门主管',
              forceSelection: true,
              triggerAction: 'all',
              selectOnFocus:true

            }
       
          ],
          buttons:[{
              id:'ok',
              text:'确定',
              handler: function(){
                if (editDepartmentForm.form.isValid()) {
                  Ext.getCmp('ok').setDisabled(true);
                  editDepartmentForm.form.submit({
                    method: 'post',
                    waitMsg: '正在保存信息...',
                    success: function(result, response){
                      if (response.result.info == "success") {
                        //添加成功后，隐藏窗口，并刷新Grid
                        editDepartmentWin.destroy();
                      }
                      else {
                        Ext.MessageBox.alert('消息', response.result.info);
                        Ext.getCmp('ok').setDisabled(false);
                      }
                    },
                    failure: function(result, response){
                      Ext.MessageBox.alert('提示', result.responseText);
                      Ext.getCmp('ok').setDisabled(false);
                    }
                  });
                }
                else {
                  Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                  
                }
              }
            },{
              text:'取消',
              handler:function(){
                editDepartmentWin.destroy();
              }
            }]
        });
        editDepartmentForm.form.load({
          url: '/department/edit?id=' + departmentId,
          success: function(form, action){
          },
          failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
          }
        });
        editDepartmentForm.render('edit_department_form');
      })
    </script>
  </head>
  <body>
    <div id="edit_department_form"></div>
  </body>
</html>
